<template>
  <el-form :model="form" label-width="70px" class="form" label-position="right">
    <el-form-item label=" 收藏夹id">
      <el-input v-model="form.favoriteId" placeholder="请填写 收藏夹id" />
    </el-form-item>
    <el-form-item label=" 创建人">
      <el-input v-model="form.createBy" placeholder="请填写创建人" />
    </el-form-item>
    <el-row v-if="popData.type !== 2">
      <el-form-item>
        <el-button type="primary" @click="edit">{{ loadingText }}</el-button>
        <el-button type="primary" @click="cancel">取消</el-button>
      </el-form-item>
      <el-col :span="6">
        <el-form-item />
      </el-col>
    </el-row>
  </el-form>
</template>
<script>
import favoriteCollection from '@/api/favoriteCollection'
export default {
  props: ['popData'],
  data() {
    return {
      form: {
        id: ''
      },
      loadingText: '保存'
    }
  },
  created() {
    const id = this.popData.id
    if (id) {
      this.form.id = id
      this.loadingText = '编辑'
      this.getDetailById(id)
    } else {
      this.loadingText = '保存'
    }
  },
  methods: {
    getDetailById(id) {
      favoriteCollection.getById(id).then(res => {
        this.form = res.data
      })
    },
    edit() {
      favoriteCollection.edit(this.form).then(res => {
        this.$message.success(res.message)
        this.$router.push('/favoriteCollect/index')
      })
    },
    cancel() {
      this.$parent.closePop()
    }
  }
}
</script>
<style>
.form{
  margin: 30px auto;
}
</style>
